dev.action = function (resp, param) {
    if (param.time == null || param.workSpace == null || param.id == null) {
        resp.setJsData('必须传入设备ID、时间参数、空间架构参数')
        return
    }
    var time = param.time;
    var workshop = param.workSpace
    var id = param.id
    var timeObj = dtime.parseStringToDateTimeViaPattern(time)

    var times = 0
    var timePattern = ''
    var flag = 0
    // 获取遍历的时间长度
    switch (time.length) {
        case 4:
            times=timeObj.monthOfYear().getMaximumValue();
            timePattern = 'yyyy-MM'
            flag = 1
            break;
        case 7:
            times=timeObj.dayOfMonth().getMaximumValue();
            timePattern = 'yyyy-MM-dd'
            flag = 2
            break;
        case 10:
            times=timeObj.hourOfDay().getMaximumValue() + 1;
            timePattern = 'yyyy-MM-dd HH'
            flag = 3
            break;
        default:
            break;
    }

    var result = iot.list();

    //开始遍历数据
    for (var i = 0; i < times; i++) {
        var newItem = {
            water: (iot.rand()*1000).toFixed(2),
            electricity: (iot.rand()*1000).toFixed(2),
            gas: (iot.rand()*1000).toFixed(2),
            heat: (iot.rand()*1000).toFixed(2),
            airPress: (iot.rand()*1000).toFixed(2),
            steam: (iot.rand()*1000).toFixed(2)
        }

        newItem.time = timeObj.toString(timePattern);
        result.add(newItem);
        // 时间递进
        if (flag == 1) {
            timeObj = timeObj.plusMonths(1);
        } else if (flag == 2) {
            timeObj = timeObj.plusDays(1);
        } else {
            timeObj = timeObj.plusHours(1);
        }
    }

    // 求和算累积量，放到最后
    var lastSum = {
        water: 0,
        electricity: 0,
        gas: 0,
        heat: 0,
        airPress: 0,
        steam: 0
    }
    for (var i = 0; i < result.length; i++) {
        for (var key in lastSum) {
            lastSum[key] += parseFloat(result[i][key])
        }
    }
    for (var key in lastSum) {
        lastSum[key] = lastSum[key].toFixed(2)
    }
    lastSum['time'] = '累积量'
    result.add(lastSum)

    var jsData = {
        length: times,
        datas: result
    }
    resp.setJsData(jsData)
}
